fix(session): preserve tool metadata across pending→running transition#20210
Open
rmk40 wants to merge 2 commits intoanomalyco:devfrom
Open
fix(session): preserve tool metadata across pending→running transition#20210rmk40 wants to merge 2 commits intoanomalyco:devfrom
rmk40 wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found a related PR: #20183 - "fix(session): preserve metadata in tool-call handler for subagent click navigation" This PR is related to your current PR (#20210) because both address the same issue with preserving tool metadata for subagent navigation in the TUI. Your PR (#20210) is actually listed as "Related: #20183" in its description, indicating they're addressing the same root problem but may have different approaches or this PR might be a refinement/follow-up. |
Add two shared test fixtures that enable E2E tests through the real AI SDK streamText pipeline without mocking: - test/fixture/anthropic.ts: fake Anthropic HTTP server with SSE response helpers (toolResponse, textResponse, waitRequest, deferred) - test/fixture/prompt-layers.ts: full SessionPrompt Effect layer stack with real LLM.defaultLayer and no-op stubs for MCP/LSP/FileTime These fixtures reduce boilerplate for tests that need to exercise the complete prompt pipeline (tool registration, resolveTools, processor event handling) against a fake provider. Closes anomalyco#20206
The AI SDK fires tool execute() as a detached promise before the
processor handles the tool-call stream event. When execute() calls
ctx.metadata({sessionId}), the processor's tool-call handler
overwrites the DB with a fresh running state that has no metadata,
making subagent sessions unclickable in the TUI.
- Add synchronous toolMetadata side-channel on processor context
- setToolMetadata() on Handle writes to the map immediately
- tool-call handler reads and merges metadata from the side-channel
- prompt.ts metadata callback calls setToolMetadata() before the
async DB update, ensuring metadata is captured regardless of
event ordering
- Add E2E regression test using fake Anthropic HTTP server through
the real AI SDK streamText pipeline with gate-based assertion of
running-state metadata
Closes anomalyco#20184
86cd7c6 to
eb71403
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #20184
Type of change
What does this PR do?
The AI SDK fires tool
execute()as a detached promise before the processor handles thetool-callstream event. Whenexecute()callsctx.metadata({sessionId}), the processor'stool-callhandler overwrites the DB with a fresh{status: "running", input, time}state that drops the metadata. This makes subagent sessions unclickable in the TUI because the TUI readsstate.metadata.sessionIdfor navigation.The fix adds a synchronous
toolMetadatamap on the processor context.setToolMetadata()on the Handle writes to this map immediately when the metadata callback fires. Thetool-callhandler then reads from the map and mergestitle/metadatainto the running state.prompt.ts's metadata callback callssetToolMetadata()synchronously before its existing async DB update, so metadata is captured regardless of event ordering.Depends on #20208 for the test fixtures.
Related: #20183
How did you verify your code works?
test/session/metadata-race.test.ts) that goes through the full production path:ToolRegistry.register→SessionPrompt.loop→resolveTools→ctx.metadata()→setToolMetadata→ processortool-callhandler. Uses the shared Anthropic server fixture from test: add reusable fixtures for E2E testing with real AI SDK pipeline #20208 with real AI SDKstreamText. Assertsmetadata.sessionIdis present on the running tool part in the DB.setToolMetadatamissing from Handle), confirming it catches the regression.prompt-effect.test.ts(23 tests) andprocessor-effect.test.ts(10 tests) still pass.Screenshots / recordings
N/A — data layer fix, not UI change.
Checklist